import redis
from dotenv import dotenv_values

from src.config import BaseConfig, config


# 开发环境
class DevelopConfig(BaseConfig):
    # mysql 配置
    MYSQL_USERNAME = config.get('MYSQL_USERNAME') or 'root'
    MYSQL_PASSWORD = config.get('MYSQL_PASSWORD')
    MYSQL_HOST = config.get('MYSQL_HOST') or '127.0.0.1'
    MYSQL_PORT = int(config.get('MYSQL_PORT') or 3306)
    MYSQL_DATABASE = config.get('MYSQL_DATABASE') or 'AdminFlask'
    # mysql 数据库的配置信息
    SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{MYSQL_USERNAME}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DATABASE}?charset=utf8mb4"

    # redis 配置
    REDIS_HOST = config.get('REDIS_HOST')
    REDIS_PORT = config.get('REDIS_PORT')
    REDIS_PASSWORD = config.get("REDIS_PASSWORD") or ""
    # REDIS_URL = f"redis://{REDIS_HOST}:{REDIS_PORT}/0"
    # print(f"redis_url = {REDIS_URL}")
    # REDIS_URL = f"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/0"
    SESSION_REDIS = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=0)  # Redis服务器配置

    # JSON配置
    JSON_AS_ASCII = False

    # Session配置
    SESSION_USE_SIGNER = False
    SESSION_COOKIE_SAMESITE = "None"
    SESSION_PERMANENT = True
    SESSION_COOKIE_SECURE = True
    SESSION_COOKIE_NAME = 'session'


# 生产环境
class ProduceConfig(BaseConfig):
    DEBUG = False

    MYSQL_USERNAME = config.get('MYSQL_USERNAME') or 'root'
    MYSQL_PASSWORD = config.get('MYSQL_PASSWORD')
    MYSQL_HOST = config.get('MYSQL_HOST') or '127.0.0.1'
    MYSQL_PORT = int(config.get('MYSQL_PORT') or 3306)
    MYSQL_DATABASE = config.get('MYSQL_DATABASE') or 'AdminFlask'

    # mysql 数据库的配置信息
    SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{MYSQL_USERNAME}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DATABASE}?charset=utf8mb4"


# 选择环境
CONFIG = {
    "dev": DevelopConfig,
    "pro": ProduceConfig
}
